package demo2;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

/**
 * DAO Data Access Object
 * 数据访问对象
 * <p>
 * DAO代表一组类，这些类在项目中负责数据库打交道
 * 可以针对某张表进行增删改查的操作
 */
@Component
@PropertySource("classpath:config.properties")
public class UserDAO {
    @Value("${spring.datasource.url}")//在属性上进行注释
    private String url;
    @Value("${spring.datasource.username}")
    private String username;
    //@Value("${spring.datasource.password}")
    private String password;

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }
    @Value("${spring.datasource.password}")//同样可以在"set()"方法上进行注释
    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public String toString() {
        return "UserDAO{" +
                "url='" + url + '\'' +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                '}';
    }
}
